# No need to weight (have used double punch)
# no race variable
# age is already in groups


library(haven)
library(tidyverse)

setwd("/Users/matteo/Desktop/Prison Polling/Prison Data Internship/Gallup and YouGov/Gallup/Gallup post 1975 polls/")


read_spss("GBSSLT1977-CQ592-3.por") %>%
  mutate(gender = case_match(Q447A,
                             1 ~ 'Male',
                             c(2,3) ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_CrimeNat = ifelse(Q016B %in% c(NA_integer_, 777), NA_integer_,
                                   tolower(as.character(as_factor(Q016B))))) %>%
  mutate(Date = '1977-11-01') %>%
  select(gender, age, Date, GP_CrimeNat) -> surveydata




read_spss("GBSSLT1978-CQ636.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_GovLongerSentences = ifelse(Q025G %in% c(NA_integer_, 777), NA_integer_,
                                        tolower(as.character(as_factor(Q025G)))),
         GP_DeathPen78 = ifelse(Q036 %in% c(NA_integer_, 777), NA_integer_,
                                tolower(as.character(as_factor(Q036))))) %>%
  select(gender, age, GP_GovLongerSentences, GP_DeathPen78) %>%
  mutate(Date = '1978-09-01') %>%
  bind_rows(surveydata, .) -> surveydata




read_spss("GBSSLT1979-CQ686A.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_DeathPen78 = ifelse(Q020B %in% c(NA_integer_, 777), NA_integer_,
                                tolower(as.character(as_factor(Q020B))))) %>%
  select(gender, age, GP_DeathPen78) %>%
  mutate(Date = '1979-09-01') %>%
  bind_rows(surveydata, .) -> surveydata




read_spss("GBSSLT1980-CQ715A.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_CrimeLocal = ifelse(Q014A %in% c(NA_integer_, 777), NA_integer_,
                              tolower(as.character(as_factor(Q014A)))),
         GP_WalkNight = case_match(Q014B, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1)) %>%
  select(gender, age, GP_CrimeLocal, GP_WalkNight) %>%
  mutate(Date = '1980-04-01') %>%
  bind_rows(surveydata, .) -> surveydata




read_spss("GBSSLT1981-CQ756.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_GovLongerSentences = ifelse(Q025N %in% c(NA_integer_, 777), NA_integer_,
                                        tolower(as.character(as_factor(Q025N))))) %>%
  select(gender, age, GP_GovLongerSentences) %>%
  mutate(Date = '1981-02-01') %>%
  bind_rows(surveydata, .) -> surveydata




read_spss("GBSSLT1981-CQ756A.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_GovLongerSentences = ifelse(Q026N %in% c(NA_integer_, 777), NA_integer_,
                                        tolower(as.character(as_factor(Q026N))))) %>%
  select(gender, age, GP_GovLongerSentences) %>%
  mutate(Date = '1981-02-01') %>%
  bind_rows(surveydata, .) -> surveydata



read_spss("GBSSLT1981-CQ777.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_CrimeNat = ifelse(Q021A %in% c(NA_integer_, 777), NA_integer_,
                                tolower(as.character(as_factor(Q021A)))),
         GP_WalkNight = case_match(Q029A, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_SocialProblemDrug = ifelse(Q019_4 %in% c(NA_integer_, 777), NA_integer_, Q019_4),
         GP_SocialProblemProstitution = ifelse(Q019_7 %in% c(NA_integer_, 777), NA_integer_, Q019_7),
         GP_SocialProblemRape = ifelse(Q019_8 %in% c(NA_integer_, 777), NA_integer_, Q019_8),
         GP_SocialProblemGang = ifelse(Q019_9 %in% c(NA_integer_, 777), NA_integer_, Q019_9),
         GP_SocialProblemJuvenileDel = ifelse(Q019_11 %in% c(NA_integer_, 777), NA_integer_, Q019_11),
         GP_SocialProblemViolence = ifelse(Q019_13 %in% c(NA_integer_, 777), NA_integer_, Q019_13),
         GP_SocialProblemOrgCrime = ifelse(Q019_14 %in% c(NA_integer_, 777), NA_integer_, Q019_14),
         GP_CauseCrime = case_match(Q024C, c(NA_integer_, 777) ~ NA_integer_, c(1,999) ~ 0, c(2,3) ~ 1),
         GP_SentTooShort = ifelse(Q034A %in% c(NA_integer_, 777), NA_integer_,
                                  tolower(as.character(as_factor(Q034A)))),
         GP_SentencingPrinciple = case_match(Q024C, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, c(1,3) ~ 1),
         GP_BringBackCat = case_match(Q036A, c(NA_integer_, 777) ~ NA_integer_, c(1,999) ~ 0, 2 ~ 1),
         GP_BringBackBirching = case_match(Q036B, c(NA_integer_, 777) ~ NA_integer_, c(1,999) ~ 0, 2 ~ 1),
         GP_BringBackCaning = case_match(Q036C, c(NA_integer_, 777) ~ NA_integer_, c(1,999) ~ 0, 2 ~ 1),
         GP_DeathPenArmy = case_match(Q038A, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenTerrorist = case_match(Q038B, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenWoman = case_match(Q038C, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenSurprise = case_match(Q038D, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenDrunk = case_match(Q038E, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenInsane = case_match(Q038F, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenProvoke = case_match(Q038G, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenFun = case_match(Q038H, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenChildRape = case_match(Q038I, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenRape = case_match(Q038J, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1)) %>%
  select(gender, age, 
         starts_with("GP_")) %>%
  mutate(Date = '1981-07-01') %>%
  bind_rows(surveydata, .) -> surveydata




read_spss("GBSSLT1982-CQ810A.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_WalkNight = case_match(Q020A, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_SocialProblemDrug = ifelse(Q018_4 %in% c(NA_integer_, 777), NA_integer_, Q018_4),
         GP_SocialProblemProstitution = ifelse(Q018_7 %in% c(NA_integer_, 777), NA_integer_, Q018_7),
         GP_SocialProblemRape = ifelse(Q018_8 %in% c(NA_integer_, 777), NA_integer_, Q018_8),
         GP_SocialProblemGang = ifelse(Q018_9 %in% c(NA_integer_, 777), NA_integer_, Q018_9),
         GP_SocialProblemJuvenileDel = ifelse(Q018_11 %in% c(NA_integer_, 777), NA_integer_, Q018_11),
         GP_SocialProblemViolence = ifelse(Q018_13 %in% c(NA_integer_, 777), NA_integer_, Q018_13),
         GP_SocialProblemOrgCrime = ifelse(Q018_14 %in% c(NA_integer_, 777), NA_integer_, Q018_14),
         GP_SentTooShort = ifelse(Q022A %in% c(NA_integer_, 777), NA_integer_,
                                  tolower(as.character(as_factor(Q022A)))),
         GP_SentencingPrinciple = case_match(Q022B, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, c(1,3) ~ 1),
         GP_BringBackCat = case_match(Q023A, c(NA_integer_, 777) ~ NA_integer_, c(1,999) ~ 0, 2 ~ 1),
         GP_BringBackBirching = case_match(Q023B, c(NA_integer_, 777) ~ NA_integer_, c(1,999) ~ 0, 2 ~ 1),
         GP_BringBackCaning = case_match(Q023C, c(NA_integer_, 777) ~ NA_integer_, c(1,999) ~ 0, 2 ~ 1),
         GP_DeathPenArmy = case_match(Q024A, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenTerrorist = case_match(Q024B, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenWoman = case_match(Q024C, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenSurprise = case_match(Q024D, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenDrunk = case_match(Q024E, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenInsane = case_match(Q024F, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenProvoke = case_match(Q024G, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenFun = case_match(Q024H, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenChildRape = case_match(Q024I, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenRape = case_match(Q024J, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1)) %>%
  select(gender, age, starts_with("GP_")) %>%
  mutate(Date = '1982-03-01') %>%
  bind_rows(surveydata, .) -> surveydata
  

  
read_spss("GBSSLT1983-CQ874.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_DeathPenArmy = case_match(Q025A, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenTerrorist = case_match(Q025B, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenWoman = case_match(Q025C, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenSurprise = case_match(Q025D, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenDrunk = case_match(Q025E, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenInsane = case_match(Q025F, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenProvoke = case_match(Q025G, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenFun = case_match(Q025H, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenChildRape = case_match(Q025I, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenRape = case_match(Q025J, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1)) %>%
  select(gender, age, starts_with("GP_")) %>%
  mutate(Date = '1983-06-01') %>%
  bind_rows(surveydata, .) -> surveydata



read_spss("GBSSLT1985-CQ987A.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_SocialProblemDrug = ifelse(Q037_3 %in% c(NA_integer_, 777), NA_integer_, Q037_3),
         GP_SocialProblemProstitution = ifelse(Q037_13 %in% c(NA_integer_, 777), NA_integer_, Q037_13),
         GP_SocialProblemRape = ifelse(Q037_4 %in% c(NA_integer_, 777), NA_integer_, Q037_4),
         GP_SocialProblemGang = ifelse(Q037_6 %in% c(NA_integer_, 777), NA_integer_, Q037_6),
         GP_SocialProblemJuvenileDel = ifelse(Q037_2 %in% c(NA_integer_, 777), NA_integer_, Q037_2),
         GP_SocialProblemViolence = ifelse(Q037_1 %in% c(NA_integer_, 777), NA_integer_, Q037_1),
         GP_SocialProblemOrgCrime = ifelse(Q037_7 %in% c(NA_integer_, 777), NA_integer_, Q037_7),
         GP_CauseCrime = case_match(Q039C, c(NA_integer_, 777) ~ NA_integer_, c(1,999) ~ 0, c(2,3) ~ 1)) %>%
  select(gender, age, starts_with("GP_")) %>%
  mutate(Date = '1985-10-01') %>%
  bind_rows(surveydata, .) -> surveydata



read_spss("GBSSLT1986-CQ004.por") %>%
  mutate(gender = case_when(Q76A == 1 ~ 'Male',
                            Q76A %in% c(2,3) ~ 'Female'),
         age = case_when(Q75 %in% c(1,2,3) ~ "18-24",
                         Q75 %in% c(4:8) ~ "25-49",
                         Q75 %in% c(9,0,'x') ~ "50-64",
                         Q75 %in% c('y') ~ "65+"),
         GP_WalkNight = case_match(Q313, '2' ~ 0, '1' ~ 1),
         GP_SocialProblemDrug = ifelse(Q311_P4 %in% c(NA_integer_, '777'), NA_integer_, Q311_P4),
         GP_SocialProblemProstitution = ifelse(Q311_P7 %in% c(NA_integer_, '777'), NA_integer_, Q311_P7),
         GP_SocialProblemRape = ifelse(Q311_P8 %in% c(NA_integer_, '777'), NA_integer_, Q311_P8),
         GP_SocialProblemGang = ifelse(Q311_P9 %in% c(NA_integer_, '777'), NA_integer_, Q311_P9),
         GP_SocialProblemJuvenileDel = ifelse(Q311C_P2 %in% c(NA_integer_, '777'), NA_integer_, Q311C_P2),
         GP_SocialProblemViolence = ifelse(Q311C_P4 %in% c(NA_integer_, '777'), NA_integer_, Q311C_P4),
         GP_SocialProblemOrgCrime = ifelse(Q311C_P5 %in% c(NA_integer_, '777'), NA_integer_, Q311C_P5),
         GP_SentTooShort = case_match(Q316, '1' ~ 'too short', '2' ~ 'too long', '3' ~ 'about right', '4' ~ 'dk'),
         GP_SentencingPrinciple = case_match(Q317, c('2','4') ~ 0, c('1','3') ~ 1),
         GP_BringBackCat = case_match(Q318, c('1','3') ~ 0, '2' ~ 1)) %>%
  select(gender, age, starts_with("GP_")) %>%
  mutate(Date = '1986-02-01') %>%
  bind_rows(surveydata, .) -> surveydata



read_spss("GBSSLT1987-CQ217A.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_SocialProblemDrug = ifelse(Q035_4 %in% c(NA_integer_, 777), NA_integer_, Q035_4),
         GP_SocialProblemProstitution = ifelse(Q035_7 %in% c(NA_integer_, 777), NA_integer_, Q035_7),
         GP_SocialProblemRape = ifelse(Q035_8 %in% c(NA_integer_, 777), NA_integer_, Q035_8),
         GP_SocialProblemGang = ifelse(Q035_9 %in% c(NA_integer_, 777), NA_integer_, Q035_9),
         GP_SocialProblemJuvenileDel = ifelse(Q035_11 %in% c(NA_integer_, 777), NA_integer_, Q035_11),
         GP_SocialProblemViolence = ifelse(Q035_13 %in% c(NA_integer_, 777), NA_integer_, Q035_13),
         GP_SocialProblemOrgCrime = ifelse(Q035_14 %in% c(NA_integer_, 777), NA_integer_, Q035_14),
         GP_SentencingPrinciple = case_match(Q037, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, c(1,3) ~ 1),
         GP_DeathPenArmy = case_match(Q038A, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenTerrorist = case_match(Q038B, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenWoman = case_match(Q038C, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenSurprise = case_match(Q038D, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenDrunk = case_match(Q038E, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenInsane = case_match(Q038F, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenProvoke = case_match(Q038G, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenFun = case_match(Q038H, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenChildRape = case_match(Q038I, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenRape = case_match(Q038J, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1)) %>%
  select(gender, age, starts_with("GP_")) %>%
  mutate(Date = '1987-10-01') %>%
  bind_rows(surveydata, .) -> surveydata



read_spss("GBSSLT1989-CQ938B.por") %>%
  mutate(gender = case_when(GENDER == 1 ~ 'Male',
                            GENDER == 2 ~ 'Female'),
         age = case_when(AGE_V4 %in% c(1,2,3) ~ "18-24",
                         AGE_V4 %in% c(4:8) ~ "25-49",
                         AGE_V4 %in% c(9,10,11) ~ "50-64",
                         AGE_V4 %in% c(12) ~ "65+"),
         GP_SentencingPrinciple = case_match(Q238, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, c(1,3) ~ 1),
         GP_DeathPenArmy = case_match(Q239A, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenTerrorist = case_match(Q239B, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenWoman = case_match(Q239C, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenSurprise = case_match(Q239D, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenDrunk = case_match(Q239E, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenInsane = case_match(Q239F, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenProvoke = case_match(Q239G, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenFun = case_match(Q239H, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenChildRape = case_match(Q239I, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1),
         GP_DeathPenRape = case_match(Q239J, c(NA_integer_, 777) ~ NA_integer_, c(2,999) ~ 0, 1 ~ 1)) %>%
  select(gender, age, starts_with("GP_")) %>%
  mutate(Date = '1989-09-01') %>%
  bind_rows(surveydata, .) -> surveydata


write_csv(surveydata, "/Users/matteo/Desktop/Prison Polling/Prison Data Internship/Survey Data/Finished/Gallup_allrepeatedcrimequestions.csv")

